<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    var obj = {
      a: 10,
      b: 20,
      c: {
        a: 10
      }
    }
    // var obj2 = obj;
    // 浅拷贝
    /* var obj2 = {};
    for(var key in obj) {
      obj2[key] = obj[key];
    }
    console.log(obj2);
    obj2.a = 500;
    // console.log(obj);
    obj2.c.a = 5000;
    console.log(obj); */
    // JSON.parse() JSON.stringify()

    // ？localStorage或者 cookie 如何存储对象 或者数组
    /* var arr = [1,2,3,45];
    localStorage.setItem('arr',JSON.stringify(arr)); */
    /* var arr = localStorage.getItem('arr')
              ?
              JSON.parse(localStorage.getItem('arr'))
              :
              []; */
    var obj = {
      a: 10,
      b: 20,
      c: {
        a: 10
      }
    }

    var obj2 = JSON.parse(JSON.stringify(obj));
    obj2.c.a = 3000;
    console.log(obj2);
    console.log(obj);

    // es6浅克隆
    // 数组
    var arr = [1,2,3,4];
    var arr2 = [...arr];
    // 对象浅克隆
    var obj = {
      a: 10,
      b: 20,
      c: 30
    }
    var obj2 = {
      ...obj
    }
  </script>
</body>
</html>